package com.tjsinfo.tjsoa.baobiao.bo;

import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.baobiao.vo.THqJshgbjbqk;
import com.tjsinfo.tjsoa.Dao.ISpringDao;


/**
 * 计划生育用户管理
 * 
 * @author 天津市电子计算机研究所
 *
 */
	
public class THqJshgbManage implements IHqJshgbManage{
	private IQbcDao qbcDao;
	private IHibernateDao hibernateDao;
	private ISpringDao springDao;
	
	public ISpringDao getSpringDao() {
		return springDao;
	}

	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}
	
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	
	/**
	 * 根据id查找
	 * @param id
	 * @return
	 */
	public THqJshgbjbqk findByid(Integer id) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqJshgbjbqk.class); 
		criteria.add(Restrictions.eq("id", id));
		return  (THqJshgbjbqk) qbcDao.getCriteria(criteria).iterator().next();
	}
	
	/**
	 * 根据yhid查找
	 * @param id
	 * @return
	 */
	public List<THqJshgbjbqk> findByyhid(Integer yhid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqJshgbjbqk.class); 
		criteria.add(Restrictions.eq("yhid", yhid));
		return  qbcDao.getCriteria(criteria);
	}

/**
 * 获取所有记录
 */
	public List<Map<String, String>> findAll() {
		// TODO Auto-generated method stub
		String[] fieldsStrings = new String[]{"id","dwmch","xm","chshny","sshbsh","zhw","zhch","gwkshshj","jtzhzh","dwdh","zhzhdh","gbid"};
		StringBuffer SQlBuffer = new StringBuffer(); 
			SQlBuffer.append("SELECT bbyh.id as id , bbyh.dwmch as dwmch , gb.xm as xm, gb.chshny as chshny, gb.sshbsh as sshbsh,");
			SQlBuffer.append("gb.zhw as zhw,gb.zhch as zhch, gb.gwkshshj as gwkshshj, gb.jtzhzh as jtzhzh, gb.dwdh as dwdh, ");
			SQlBuffer.append("gb.zhzhdh as zhzhdh, gb.id as gbid ");
			SQlBuffer.append("FROM t_hq_baobiaouser as bbyh LEFT OUTER JOIN t_hq_jshgbjbqk as gb ON bbyh.id=gb.yhid ");
			SQlBuffer.append("where bbyh.bbid=1 and bbyh.state='1' order by bbyh.sort");
		List<Map<String, String>> tempList = springDao.commonSelect(fieldsStrings, SQlBuffer.toString());
		return tempList;		
	}
	
/**
 * 添加记录
 */
	public void add(THqJshgbjbqk gbtemp) {
	// TODO Auto-generated method stub
	    hibernateDao.save(gbtemp);
	}

/**
 * 更新记录
 */
	
	public void update(THqJshgbjbqk gbtemp) {
	// TODO Auto-generated method stub
		hibernateDao.update(gbtemp);
	}
}


